package com.aero.cojbackenduserservice.controller.inner;

import com.aero.cojbackendmodel.model.entity.User;
import com.aero.cojbackendserviceclient.service.UserFeignClient;
import com.aero.cojbackenduserservice.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * 该服务仅内部调用，不是给前端的
 */
@RestController
@RequestMapping("/inner")
public class UserInnerController implements UserFeignClient {

    @Resource
    private UserService userService;


    /**
     * 根据 id 获取用户
     * @param userId
     * @return
     */
    @Override
    @GetMapping("/get/id")
    public User getById(@RequestParam("userId") long userId) {
        return userService.getById(userId);
    }

    /**
     * 根据 id 获取用户列表
     * @param idList
     * @return
     */
    @Override
    @GetMapping("/get/ids")
    public List<User> listByIds(@RequestParam("idList") Collection<Long> idList) {
        return userService.listByIds(idList);
    }

    @Override
    @GetMapping("/updateUserCompletionAndScore")
    public Boolean updateUserCompletionAndScore(@RequestParam("userId") Long userId, @RequestParam("questionId") Long questionId) {
        return userService.updateUserCompletionAndScore(userId, questionId);
    }

    @PostMapping("/addScore")
    public void addScore(@RequestParam("user") String user, @RequestParam("score") double score) {
        userService.addScore(user, score);
    }

    // 获取指定用户的分数
    @GetMapping("/getScore")
    public Double getScore(@RequestParam("user") String user) {
        return userService.getScore(user);
    }

}
